<?php if($this->userData) {
    /*
$tab_bony = array(
	'pl'	=> array(
					'200' => 'carnauba_bon.jpg',
					'300' => 'carnauba_bon.jpg',
					'400' => 'carnauba_bon.jpg',
					'500' => 'carnauba_bon.jpg',
					'600' => 'carnauba_bon.jpg',
					'700' => 'carnauba_bon.jpg',
					'800' => 'carnauba_bon.jpg'
				),
	'en'	=> array(),
	'cs'	=> array()
);
*/
$tab_bony['pl']['200']['jpg'] = 'carnauba_bon.jpg';
$tab_bony['pl']['200']['price'] = '20.00 zł';
$tab_bony['pl']['200']['name'] = 'Bon podarunkowy carnauba 200';
$tab_bony['pl']['300']['jpg'] = 'carnauba_bon.jpg';
$tab_bony['pl']['300']['price'] = '30.00 zł';
$tab_bony['pl']['300']['name'] = 'Bon podarunkowy carnauba 300';
$tab_bony['pl']['400']['jpg'] = 'carnauba_bon.jpg';
$tab_bony['pl']['400']['price'] = '40.00 zł';
$tab_bony['pl']['400']['name'] = 'Bon podarunkowy carnauba 400';
$tab_bony['pl']['500']['jpg'] = 'carnauba_bon.jpg';
$tab_bony['pl']['500']['price'] = '50.00 zł';
$tab_bony['pl']['500']['name'] = 'Bon podarunkowy carnauba 500';
$tab_bony['pl']['600']['jpg'] = 'carnauba_bon.jpg';
$tab_bony['pl']['600']['price'] = '60.00 zł';
$tab_bony['pl']['600']['name'] = 'Bon podarunkowy carnauba 600';
?>
<h2 class="bold acenter"><?php echo strtoupper($this->translate( 'bon_kod_rab' )); ?></h2>
<div class="content">
<?php if( $this->error != '' ) { ?>

	<?php if($this->formplatnosci) {?>
			<div style="text-align:center; margin-bottom:10px"><?php  echo $this->error ?></div>
	<?php } else {?>
			<h3><?php echo $this->translate( $this->error ); ?></h3>
	<?php }?>
	

<?php } ?>

<?php echo $this->inlineScript()->setScript('
var mancheck;
$("#document").ready(function(){
$("#facture-form").validate({
	rules: {
		dar_email : {
			required: true,
			email: true
		},
		fv_locality : {
			required: true,
			minlength: 2
		},
		fv_street : {
			required: true,
			minlength: 2
		},
		fv_nr_home : {
			required: true
		},
		fv_zip : {
			required: true,
			minlength: 2
		}
	},
	messages: {
		dar_email : "'. $this->translate( 'error_email' ) .'",
		fv_locality : "'. $this->translate( 'error_locality' ) .'",
		fv_street : "'. $this->translate( 'error_street' ) .'",
		fv_nr_home : "'. $this->translate( 'error_nr_home' ) .'",
		fv_nr_flat :  "'. $this->translate( 'error_nr_flat' ) .'",
		fv_zip : "'. $this->translate( 'error_zip' ) .'"
	}
});

mancheck = function() {
	var items = $("td.mancheck");	
	var inputs = items.find( "input" );
	var err = 0;
	
	if( ( $( inputs[0] ).val() == "" ) && ( $( inputs[1] ).val() == "" ) ) {
		if( $( inputs[2] ).val() == "" ) {
			$( items[2] ).find( "label" ).css({ display: "block" });
			err++;
		} else {
			$( items[2] ).find( "label" ).css({ display: "none" });
			err--;
		}
		
		if( $( inputs[3] ).val() == "" ) {
			$( items[3] ).find( "label" ).css({ display: "block" });
			err++;
		} else {
			$( items[3] ).find( "label" ).css({ display: "none" });
			err--;
		}
	}
	
	return ( err > 0 ) ? false : true;
};

})') ?>

<form onsubmit="return mancheck()" id="facture-form" method="post">		
	
		<?php foreach ($tab_bony[$this->locale] as $war => $val) { ?>
		
			<div class="box">
				<div class="column">
					<div class="colimg" style="background-color:transparent; height:auto"><img src="{baseUrl}/public/images/<?php echo $val['jpg'];?>" alt=""></div>
					<div class="coltext">
						<div class="prod">
							<div class="name"><?php echo strtoupper($val['name']); ?><span class="price"><?php echo $val['price']; ?></span></div>
							<div class="avail" style="position:relative; top:17px">
								<a href="javascript:;" onClick="$('#id_bonu').attr('value','<?php echo $war?>'); $('#facture-form').submit();" class="button"><?php echo $this->translate( 'checkout' ); ?></a>
							</div>
						</div> 
					</div>
				<div class="clr"></div>
				</div>
				<div class="end"></div>
			</div>
		<?php }?>

	
	<h2><?php echo $this->translate( 'facture_info' ) ?></h2>
	<input type="hidden" name="id_bonu" id="id_bonu" value="0" /> 
	<div class="box">
	
	<table class="tab">
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'voucher_email' ) ?></td>
			<td><input type="text" id="cdar_email" name="dar_email" value="<?php echo $this->dar_email ?>"></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'nip' ) ?>:</td>
			<td><input type="text" id="cfv_nip" name="fv_nip" value="<?php echo $this->fv_nip ?>" ><label class="error" style="display:none"><?php echo $this->translate( 'error_company' ) ?></label></td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'company_name' ) ?>:</td>
			<td>
				<input type="text" id="cfv_company_name" name="fv_company_name" value="<?php echo $this->fv_company_name ?>">
				<label class="error" style="display:none"><?php echo $this->translate( 'error_company' ) ?></label>
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'name' ) ?>:</td>
			<td>
				<input type="text" id="cfv_name" name="fv_name" value="<?php echo $this->fv_name ?>" >
				<label class="error" style="display:none"><?php echo $this->translate( 'error_name' ) ?></label>
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'surname' ) ?>:</td>
			<td>
				<input type="text" id="cfv_surname" name="fv_surname" value="<?php echo $this->fv_surname ?>" >
				<label class="error" style="display:none"><?php echo $this->translate( 'error_surname' ) ?></label>
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'province' ); ?>:</td>
			<td>
				<?php echo $this->formSelect( 'fv_province', $this->fv_province, array(), Core_Static::$province ) ?>
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'country' ); ?>
			<td>
				<?php echo $this->formSelect( 'fv_country', ( $this->fv_country ) ? $this->fv_country : 'PL', array(), Core_Static::$country ) ?>
				<?php echo $this->inlineScript()->setScript( '
					$( "#fv_country" ).change(function(){
						console.log( $(this).val() );
						
						if( $(this).val() != "PL" ) {
							$( "#fv_province" ).animate({ opacity: 0 });
						} else {
							$( "#fv_province" ).animate({ opacity: 1 });
						}
		
					});
				' ); ?>
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'locality' ) ?>:</td>
			<td>
				<input type="text" id="cfv_locality" name="fv_locality" value="<?php echo $this->fv_locality ?>" >
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'street' ) ?>:</td>
			<td>
				<input type="text" id="cfv_street" name="fv_street" value="<?php echo $this->fv_street ?>" >
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'nr_home2' ) ?>:</td>
			<td>
				<input type="text" id="cfv_nr_home" name="fv_nr_home" value="<?php echo $this->fv_nr_home ?>" >
			</td>
		</tr>
		<tr>
			<td class="aright"><?php echo $this->translate( 'nr_flat' ) ?>:</td>
			<td>
				<input type="text" id="cfv_nr_flat" name="fv_nr_flat" value="<?php echo $this->fv_nr_flat ?>" >
			</td>
		</tr>
		<tr>
			<td class="aright"><span class="star">*</span><?php echo $this->translate( 'zip' ) ?>:</td>
			<td>
				<input type="text" id="cfv_zip" name="fv_zip" value="<?php echo $this->fv_zip ?>" >
			</td>
		</tr>
	</table>
	
	<div class="end"></div>
</div>
</form>
</div>
<?php } else { ?>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/jquery.md5.js"></script>

<h2 class="bold aleft tindent15"><?php echo $this->translate( 'bon_kod_rab' ); ?></h2>
<div class="content">
	<?php echo $this->inlineScript()->setScript('
		$.validator.setDefaults({
			submitHandler: function(e) { 
				
				$("#login-form5").animate({
					opacity: 0
				});
				$.post(
					baseUrl + "/index/login",
					{
						login : $( "#cemail" ).val(),
						password : $.md5( $(  "#cpass" ).val() ),
						json : true
					},
					function( resp ){
						if( resp.status ) {
							window.location.reload();
							//return false;
						} else {
							alert( "' . $this->translate( 'error_login' ) . '" );
							$("#login-form5").animate({
								opacity: 1
							});
						}
					},
					"json"
				);
			}
		});
	function sprawdz_log(){
			$("#form1log").validate({
				rules: {
					email : {
						required: true,
						email: true
					},
					pass : {
						required: true,
						minlength: 2
					}
				},
				messages: {
					email : "' . $this->translate( 'error_email' ) . '",
					pass : "'. $this->translate( 'error_password' ) .'"
				}
			});
			$("#form1log").submit();
		}
	') ?>
</div>
<div class="box nomtop" id="login-form5">

<h1><?php echo $this->translate( 'shop_bon_logowanie' ); ?></h1>

<form id="form1log" onsubmit="return false" method="post" action="">
<table class="tab">
	<tr>
		<td class="aright"><?php echo $this->translate( 'shop_bon_login' ); ?>:</td>
		<td><input type="text" name="email" value="" class="type5" id="cemail"></td>
	</tr>
	<tr>
		<td class="aright"><?php echo $this->translate( 'shop_bon_pass' ); ?>:</td>
		<td><input type="password" name="password" value="" class="type5" id="cpass"></td>
	</tr>
</table>
</form>

<div class="line" style="margin:10px 0"></div>

<div class="acenter">
<a href="javascript:;" class="button" onclick="sprawdz_log()"><?php echo $this->translate( 'shop_bon_logowanie' ); ?></a>
</div>

<div class="acenter" style="margin-top:20px">
<p><a href="{baseUrl}/index/newaccount" onclick="$('#form1log').submit();" class="orange"><?php echo $this->translate( 'basket_newaccount' ) ?></a> <span style="margin:0 10px">/</span> <a href="{baseUrl}/index/remindpass"><?php echo $this->translate( 'basket_remind' ) ?></a></p>
</div>

<div class="end"></div>

	
</div>
<?php }?>